﻿using System;
using System.Windows;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCS.UI.Utils;
using System.Collections.Generic;

namespace Baosight.ZNH.ZMCS.UI
{
    /// <summary>
    /// 系统参数设置
    /// </summary>
    /// Title:ZMCS16
    /// 对应后台：ServiceZMCS16.java
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 严洪浩
    /// Version: 1.0
    /// History:
    ///       2010-05-27  严洪浩   [创建]
    ///
    public partial class ZMCS16 : EFViewCmes
    {
        public ZMCS16()
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
        }

        /// <summary>
        /// 在操作之前
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.InsertPanel.GetChildObjects<EFDataField>(null, true);
            _view.ListPageNo = "ZMCS16";
            _view.ViewType = "details";

            _view.Args.Add("fdModuleNo", this.fdModuleNo.GetDataValue().ToString());
            base.ViewProperty = _view;
        }

        public override void Initialize(EIInfo initData)
        {
            SystemSettingBlock _block = new SystemSettingBlock();
            initData.AddBlock(_block.GetIsCheck());
            initData.AddBlock(_block.GetCMSetting());

            base.Initialize(initData);
            //判断页面时新增页还是编辑页
            InitDataSet(initData);
        }

        /// <summary>
        /// 给Mode付值
        /// </summary>
        /// <param name="initData"></param>
        private void InitDataSet(EIInfo initData)
        {
            Mode = (OperationMode)Enum.Parse(typeof(OperationMode), "Update", true);
        }

        /// <summary>
        /// 第一个EFRegion修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnUpdateButtonClick(object sender, RoutedEventArgs e)
        {
            base.OnSureButtonClick(sender, e);
        }

        /// <summary>
        /// 第二个EFRegion修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnModifyButtonClick(object sender, RoutedEventArgs e)
        {
            base.CmesSureRecordBtn("ZMCS16", "updateOther", "result", sender, e);
        }

        /// <summary>
        /// 更新前的日期校验
        /// </summary>
        /// <returns></returns>
        public override bool ThisValidateField()
        {
            if (TwoGrid.ValidateField())
            {
                if (int.Parse(this.fdPlanBeginDate.Value.ToString()) > int.Parse(this.fdMonthPlanDate.Value.ToString()))
                {
                    base.OpenEFWindowAlert("月度计划截止日不能小于月度计划开始日！", true);
                    return false;
                }
                if (int.Parse(this.fdUrgentPlanDate.Value.ToString()) > int.Parse(this.fdMiddlePlanDate.Value.ToString()))
                {
                    base.OpenEFWindowAlert("中旬计划截止日不能小于中旬计划开始日！", true);
                    return false;
                }
            }
            return true;
        }

        /// <summary>
        /// 页签切换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EFTab_SelectionChanged(object sender, RoutedEventArgs e)
        {
            EFTab _tab = sender as EFTab;
            if (null != _tab)
            {
                EFTabItem _item = _tab.SelectedItem as EFTabItem;

                if (null != _item && _item.Name == "BusinessFilterTAB")
                {
                    Dictionary<string, string> _args = new Dictionary<string, string>();
                    //_args.Add("fdModuleNo", this.fdModuleNo.GetDataValue().ToString());
                    _args.Add("fdModuleNo", "ZMCM");
                    this.BusinessFilterTAB.LoadView<EFTabItem>("ZMCS17", _args);//ZMCS17业务过滤页面
                }
            }
        }

        #region 页面操作事件

        private void fdInventoryNo_Loaded(object sender, RoutedEventArgs e)
        {
            var _value = this.fdInventoryNo.Value;
            if (null != _value && _value.ToString() == "1")
            {
                this.fdInventoryNoRule.IsReadOnly = true;
            }
        }

        private void fdInventoryNo_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            string _value = e.NewValue as string;

            if (null == _value)
            {
                //this.fdEngineeringNoRule.IsReadOnly = true;
            }
            else if (_value == "1")
            {
                this.fdInventoryNoRule.IsReadOnly = true;
            }
            else
            {
                this.fdInventoryNoRule.IsReadOnly = false;
            }
        }

        private void fdApplicationNo_Loaded(object sender, RoutedEventArgs e)
        {
            var _value = this.fdApplicationNo.Value;
            if (null != _value && _value.ToString() == "1")
            {
                this.fdApplicationNoRule.IsReadOnly = true;
            }
        }

        private void fdApplicationNo_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            string _value = e.NewValue as string;

            if (null == _value)
            {
                //this.fdEngineeringNoRule.IsReadOnly = true;
            }
            else if (_value == "1")
            {
                this.fdApplicationNoRule.IsReadOnly = true;
            }
            else
            {
                this.fdApplicationNoRule.IsReadOnly = false;
            }
        }

        private void fdImportNo_Loaded(object sender, RoutedEventArgs e)
        {
            var _value = this.fdImportNo.Value;
            if (null != _value && _value.ToString() == "1")
            {
                this.fdImportNoRule.IsReadOnly = true;
            }
        }

        private void fdImportNo_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            string _value = e.NewValue as string;

            if (null == _value)
            {
                //this.fdEngineeringNoRule.IsReadOnly = true;
            }
            else if (_value == "1")
            {
                this.fdImportNoRule.IsReadOnly = true;
            }
            else
            {
                this.fdImportNoRule.IsReadOnly = false;
            }
        }

        private void fdExportNo_Loaded(object sender, RoutedEventArgs e)
        {
            var _value = this.fdExportNo.Value;
            if (null != _value && _value.ToString() == "1")
            {
                this.fdExportNoRule.IsReadOnly = true;
            }
        }

        private void fdExportNo_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            string _value = e.NewValue as string;

            if (null == _value)
            {
                //this.fdEngineeringNoRule.IsReadOnly = true;
            }
            else if (_value == "1")
            {
                this.fdExportNoRule.IsReadOnly = true;
            }
            else
            {
                this.fdExportNoRule.IsReadOnly = false;
            }
        }
        #endregion

    }
}
